package org.hgvc.webapp.ets.jsf.beans.mastersetup;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.component.UIParameter;
import javax.faces.event.ActionEvent;

import org.hgvc.webapp.ets.bo.Agent;
import org.hgvc.webapp.ets.bo.HotelRciResort;
import org.hgvc.webapp.ets.constant.CommonConstant;
import org.hgvc.webapp.ets.spring.service.MasterSetupService;
import org.jocsb.base.AbstractBean;
import org.jocsb.base.exception.BaseException;


public class RciResortBean extends AbstractBean {
	public static final String BEAN_NAME="rciResortBean";
	private MasterSetupService service;
	private List<HotelRciResort> rciResortList;
	private HotelRciResort rciResort;
	public static final String NAV_LIST_HOTELRCIRESORT="listRciResort";
	public static final String NAV_ADD_HOTELRCIRESORT="addRciResort";
	public static final String NAV_EDIT_HOTELRCIRESORT="editRciResort";
	 
	public MasterSetupService getService() {
		return service;
	}
	public void setService(MasterSetupService service) {
		this.service = service;
	}
	public HotelRciResort getRciResort() {
		return rciResort;
	}
	public void setRciResort(HotelRciResort rciResort) {
		this.rciResort = rciResort;
	}
	public List<HotelRciResort> getHotelRciResortList() {
		try{
			rciResortList = service.getHotelRciResortList();
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		return rciResortList;
	}
	public void setHotelRciResortList(List<HotelRciResort> rciResortList) {
		this.rciResortList = rciResortList;
	}
	
	public String navCreationAction(){
		rciResort = new HotelRciResort();
		return NAV_ADD_HOTELRCIRESORT;
	}
	
	public String createAction(){
		try{
			rciResort.setCreatedBy(getThisUser());
			rciResort.setCreatedDate(new Date());
			rciResort.setIsDeleted(CommonConstant.NOT_DELETED);
			service.saveHotelRciResort(rciResort);
			return NAV_LIST_HOTELRCIRESORT;
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		return NAV_ADD_HOTELRCIRESORT;
	}
	
	public void editListener(ActionEvent actionEvent){
		rciResort = null;
		UIParameter parameter = (UIParameter)actionEvent.getComponent().findComponent("rciResortId");
		String rciResortId = (String)parameter.getValue();
		for(HotelRciResort a:rciResortList){
			if(a.getHotelRciResortId().equalsIgnoreCase(rciResortId)){
				rciResort = a;
				break;
			}
		}
	}
	
	public String navEditAction(){
		return NAV_EDIT_HOTELRCIRESORT;
	}
	
	public String editAction(){
		try{
			rciResort.setModifiedBy(getThisUser());
			rciResort.setModifiedDate(new Date());
			service.updateHotelRciResort(rciResort);
			return NAV_LIST_HOTELRCIRESORT;
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		
		return NAV_EDIT_HOTELRCIRESORT;
	}
	
	public String deleteAction(){
		try{
			
			List<HotelRciResort> deleteList = new ArrayList<HotelRciResort>();
			for(HotelRciResort a:rciResortList){
				if(a.isMarkAsAction()){
					deleteList.add(a);
				}
			}
			service.deleteHotelRciResorts(deleteList);
		}catch(BaseException ex){
			ex.printStackTrace();
			initErrorBean(ex);
		}
		return NAV_LIST_HOTELRCIRESORT;
	}
}
